<?php
	namespace Admin\Controller;

	class ArgumentsController extends CommonController{

		public function index(){
			$model=M('Arguments');
			$total=$model->count();
			$page=new \Think\Page($total,3);
			$page->setConfig('prev',上一页);
			$page->setConfig('next',下一页);
			$page_str=$page->show();
			$limit=$page->firstRow.','.$page->listRows;
			$list=$model->limit($limit)->select();
			if(!empty($list)){
				foreach($list as $key=>$value){
					$usermodel=M('user');
					$list[$key]['uname']=$usermodel->where("id=".$value['uid'])->find()['name'];
					$listmodel=M('order_list');
					$list[$key]['olb']=$listmodel->where('id='.$value['order_id'])->find()['ordernumber'];
					$infomodel=M('order_info');
					$gid=$infomodel->where('order_id='.$value['order_id'])->find()['goods_id'];
					$gmodel=M('Goods');
					$list[$key]['gname']=$gmodel->where("id=".$gid)->find()['name'];
					$gimodel=M('Goods_img');
					$giname=$gimodel->where("goods_id=".$gid)->find()['name'];
					$giname='/Public/Uploads/'.substr($giname,0,4).'/'.substr($giname,4,2).'/'.substr($giname,6,2).'/80_'.$giname;
					$list[$key]['giname']=$giname;
				}
			
			// var_dump($list);
			$this->assign('list',$list);
			$this->assign('Page',$page_str);
			}
			$this->display();
		}

		public function status(){
			$id=$_GET['id'];
			$model=M('Arguments');
			$list=$model->where("id=".$id)->find();
			if($list['status']){
				$data['status']=0;
			}else{
				$data['status']=1;
			}
			$res=$model->where("id=".$id)->save($data);
			if($res){
				$this->redirect('Arguments/index');
				return false;
			}else{
				$this->error('修改状态失败');
				return false;
			}
		}
		public function  reply(){
			$id=$_GET['id'];
			if(!$id){
				$this->redirect('Arguments/index');
				return false;
			}
			$model=M('Arguments');
			$list=$model->where("id=".$id)->select();
			foreach($list as $key=>$value){
				$usermodel=M('user');
				$list[$key]['uname']=$usermodel->where("id=".$value['uid'])->find()['name'];
				$listmodel=M('order_list');
				$list[$key]['olb']=$listmodel->where('id='.$value['order_id'])->find()['ordernumber'];
				$infomodel=M('order_info');
				$gid=$infomodel->where('order_id='.$value['order_id'])->find()['goods_id'];
				$gmodel=M('Goods');
				$list[$key]['gname']=$gmodel->where("id=".$gid)->find()['name'];
				$gimodel=M('Goods_img');
				$giname=$gimodel->where("goods_id=".$gid)->find()['name'];
				$giname='/Public/Uploads/'.substr($giname,0,4).'/'.substr($giname,4,2).'/'.substr($giname,6,2).'/80_'.$giname;
				$list[$key]['giname']=$giname;
			}
			$this->assign('list',$list);
			$this->display();
		}
		public function doreply(){
			$id=$_GET['id'];
			if(!$id){
				$this->redirect('Arguments/index');
				return false;
			}
			if(empty($_POST['rtext'])){
				$this->error('内容不能为空');
			}
			$data['rtext']=$_POST['rtext'];
			$model=M('Arguments');
			$res=$model->where("id=".$id)->save($data);
			if($res){
				$this->success('回复成功',U('Arguments/index'),2);
			}else{
				$this->error('回复失败');
			}

		}
	}